package org.hgvc.webapp.ets.spring.service;

import java.util.ArrayList;
import java.util.List;

import org.hgvc.webapp.ets.bo.Agent;
import org.hgvc.webapp.ets.bo.Branch;
import org.hgvc.webapp.ets.bo.Calendar;
import org.hgvc.webapp.ets.bo.Country;
import org.hgvc.webapp.ets.bo.Currency;
import org.hgvc.webapp.ets.bo.CurrencyRate;
import org.hgvc.webapp.ets.bo.DocControl;
import org.hgvc.webapp.ets.bo.DownPaymentInstallmentSchema;
import org.hgvc.webapp.ets.bo.HotelRciResort;
import org.hgvc.webapp.ets.bo.HotelResort;
import org.hgvc.webapp.ets.bo.HotelRoomType;
import org.hgvc.webapp.ets.bo.InstallmentSchema;
import org.hgvc.webapp.ets.bo.Nationality;
import org.hgvc.webapp.ets.bo.PaymentMode;
import org.hgvc.webapp.ets.bo.Product;
import org.hgvc.webapp.ets.bo.Race;
import org.hgvc.webapp.ets.bo.Remark;
import org.hgvc.webapp.ets.bo.Salutation;
import org.hgvc.webapp.ets.bo.State;
import org.hgvc.webapp.ets.bo.Status;
import org.hgvc.webapp.ets.bo.Territory;
import org.hgvc.webapp.ets.bo.TransactionType;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hgvc.webapp.ets.spring.dao.MasterSetupHbmDao;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.SpringUtils;


public class MasterSetupServiceImpl implements MasterSetupService{
	private MasterSetupHbmDao masterSetupDao;

	public void setMasterSetupDao(MasterSetupHbmDao masterSetupDao) {
		this.masterSetupDao = masterSetupDao;
	}

	public List<Nationality> getNationalityList()throws BaseException{
		List<Nationality> list = new ArrayList<Nationality>();
		try{
			list=masterSetupDao.getNationalityList();
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.list.object", new Object[]{Nationality.class.getSimpleName()}));
		}
		return list;
	}
	public void saveNationality(Nationality nationality)throws BaseException{
		try{
			masterSetupDao.save(nationality);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.save.object", new Object[]{Nationality.class.getSimpleName()}));
		}
	}
	public void updateNationality(Nationality nationality)throws BaseException{
		try{
			masterSetupDao.update(nationality);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.update.object", new Object[]{Nationality.class.getSimpleName()}));
		}
	}
	public void deleteNationality(List<Nationality> deleteList)throws BaseException{
		try{
			for (Nationality n : deleteList){
				n.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(n);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.object", new Object[]{Nationality.class.getSimpleName()}));
		}
	}
	
	
	public List<Country> getCountryList()throws BaseException{
		List<Country> list=new ArrayList<Country>();

		try{
			list = masterSetupDao.getPropertyObjectList(Country.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.country", new Object[]{}));
		}
		return list;
	}
	public void saveCountry(Country country)throws BaseException{
		try{

			List<Country> duplicate = masterSetupDao.getCountryByCodeOrDesc(country.getCode(), country.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.country", new Object[]{}));
			masterSetupDao.save(country);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.country", new Object[]{}));
		}
	}

	public void updateCountry(Country country)throws BaseException{
		try{
			masterSetupDao.clear();
			List<Country> duplicate = masterSetupDao.getCountryByCodeOrDesc(country.getCode(), country.getDesc());
			if(duplicate!=null){
				for(Country c:duplicate){
					if(!c.getCountryId().equalsIgnoreCase(country.getCountryId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.country", new Object[]{}));
				}
			}
			masterSetupDao.merge(country);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.country", new Object[]{}));
		}
	}

	public void deleteCountries(List<Country> countries)throws BaseException{
		try{
			for(Country country:countries){
				country.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(country);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.country", new Object[]{}));
		}
	}

	//state
	public List<State> getStateList(String countryId)throws BaseException{
		List<State> list=new ArrayList<State>();

		try{
			list = masterSetupDao.getStatesByCountryId(countryId);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.list.state", new Object[]{}));
		}
		return list;
	}
	public void saveState(State state,Country country)throws BaseException{
		try{

			List<State> duplicate = masterSetupDao.getStateByCodeOrDesc(state.getCode(), state.getDesc(),country.getCountryId());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.state", new Object[]{}));
			masterSetupDao.save(state);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.state", new Object[]{}));
		}
	}

	public void updateState(State state,Country country)throws BaseException{
		try{
			List<State> duplicate = masterSetupDao.getStateByCodeOrDesc(state.getCode(), state.getDesc(),country.getCountryId());
			if(duplicate!=null){
				for(State s:duplicate){
					if(!s.getStateId().equalsIgnoreCase(state.getStateId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.state", new Object[]{}));
				}
			}
			masterSetupDao.merge(state);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.state", new Object[]{}));
		}
	}

	public void deleteStates(List<State> states)throws BaseException{
		try{
			for(State state:states){
				state.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(state);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.state", new Object[]{}));
		}
	}

	//salutation
	public List<Salutation> getSalutationList()throws BaseException{
		List<Salutation> list=new ArrayList<Salutation>();

		try{
			list = masterSetupDao.getPropertyObjectList(Salutation.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.salutation", new Object[]{}));
		}
		return list;
	}
	public void saveSalutation(Salutation salutation)throws BaseException{
		try{

			List<Salutation> duplicate = masterSetupDao.getSalutationByDesc(salutation.getDesc(),salutation.getCode());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.salutation", new Object[]{}));
			masterSetupDao.save(salutation);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.salutation", new Object[]{}));
		}
	}

	public void updateSalutation(Salutation salutation)throws BaseException{
		try{
			List<Salutation> duplicate = masterSetupDao.getSalutationByDesc(salutation.getDesc(),salutation.getCode());
			if(duplicate!=null){
				for(Salutation s: duplicate){
					if(!s.getSalutationId().equalsIgnoreCase(salutation.getSalutationId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.salutation", new Object[]{}));
				}
			}
			masterSetupDao.merge(salutation);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.salutation", new Object[]{}));
		}
	}

	public void deleteSalutation(List<Salutation> salutations)throws BaseException{
		try{
			for(Salutation salutation:salutations){
				salutation.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(salutation);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.salutation", new Object[]{}));
		}
	}
	//race
	public List<Race> getRaceList()throws BaseException{
		List<Race> list=new ArrayList<Race>();

		try{
			list = masterSetupDao.getPropertyObjectList(Race.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.race", new Object[]{}));
		}
		return list;
	}
	public void saveRace(Race race)throws BaseException{
		try{

			List<Race> duplicate = masterSetupDao.getRaceByCodeOrDesc(race.getCode(), race.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.race", new Object[]{}));
			masterSetupDao.save(race);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.race", new Object[]{}));
		}
	}

	public void updateRace(Race race)throws BaseException{
		try{
			List<Race> duplicate = masterSetupDao.getRaceByCodeOrDesc(race.getCode(), race.getDesc());
			if(duplicate!=null){
				for(Race r:duplicate){
					if(!r.getRaceId().equalsIgnoreCase(race.getRaceId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.race", new Object[]{}));
				}
			}
			masterSetupDao.merge(race);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.race", new Object[]{}));
		}
	}

	public void deleteRaces(List<Race> races)throws BaseException{
		try{
			for(Race race:races){
				race.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(race);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.race", new Object[]{}));
		}
	}
	//Branch
	public List<Branch> getBranchList()throws BaseException{
		List<Branch> list=new ArrayList<Branch>();

		try{
			list = masterSetupDao.getPropertyObjectList(Branch.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.branch", new Object[]{}));
		}
		return list;
	}
	public void saveBranch(Branch branch)throws BaseException{
		try{

			List<Branch> duplicate = masterSetupDao.getBranchByCodeOrDesc(branch.getCode(), branch.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.branch", new Object[]{}));
			masterSetupDao.save(branch);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.branch", new Object[]{}));
		}
	}

	public void updateBranch(Branch branch)throws BaseException{
		try{
			List<Branch> duplicate = masterSetupDao.getBranchByCodeOrDesc(branch.getCode(), branch.getDesc());
			if(duplicate!=null){
				for(Branch b:duplicate){
					if(!b.getBranchId().equalsIgnoreCase(branch.getBranchId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.branch", new Object[]{}));
				}
			}
			masterSetupDao.merge(branch);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.branch", new Object[]{}));
		}
	}

	public void deleteBranches(List<Branch> branches)throws BaseException{
		try{
			for(Branch branch:branches){
				branch.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(branch);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.branch", new Object[]{}));
		}
	}

	//Agent
	public List<Agent> getAgentList()throws BaseException{
		List<Agent> list=new ArrayList<Agent>();

		try{
			list = masterSetupDao.getPropertyObjectList(Agent.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.agent", new Object[]{}));
		}
		return list;
	}
	public void saveAgent(Agent agent)throws BaseException{
		try{

		/*	List<Agent> duplicate = masterSetupDao.getAgentByCodeOrDescOrEmail(agent.getCode(), agent.getDesc(),agent.getEmail());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.agent", new Object[]{}));
			masterSetupDao.save(agent);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;*/
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.agent", new Object[]{}));
		}
	}

	public void updateAgent(Agent agent)throws BaseException{
		try{
			/*List<Agent> duplicate = masterSetupDao.getAgentByCodeOrDescOrEmail(agent.getCode(), agent.getDesc(),agent.getEmail());
			if(duplicate!=null){
				for(Agent a:duplicate){
					if(!a.getAgentId().equalsIgnoreCase(agent.getAgentId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.agent", new Object[]{}));
				}
			}
			masterSetupDao.merge(agent);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;*/
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.agent", new Object[]{}));
		}
	}

	public void deleteAgents(List<Agent> agents)throws BaseException{
		try{
			for(Agent agent:agents){
				agent.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(agent);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.agent", new Object[]{}));
		}
	}


	//Status
	public List<Status> getStatusList()throws BaseException{
		List<Status> list=new ArrayList<Status>();

		try{
			list = masterSetupDao.getPropertyObjectList(Status.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.status", new Object[]{}));
		}
		return list;
	}
	public void saveStatus(Status status)throws BaseException{
		try{

			List<Status> duplicate = masterSetupDao.getStatusByCodeOrDesc(status.getCode(), status.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.status", new Object[]{}));
			masterSetupDao.save(status);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.status", new Object[]{}));
		}
	}

	public void updateStatus(Status status)throws BaseException{
		try{
			List<Status> duplicate = masterSetupDao.getStatusByCodeOrDesc(status.getCode(), status.getDesc());
			if(duplicate!=null){
				for(Status s: duplicate){
					if(!s.getStatusId().equalsIgnoreCase(status.getStatusId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.status", new Object[]{}));
				}
			}
			masterSetupDao.merge(status);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.status", new Object[]{}));
		}
	}

	public void deleteStatuses(List<Status> statuses)throws BaseException{
		try{
			for(Status status:statuses){
				status.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(status);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.status", new Object[]{}));
		}
	}

	//TransactionType
	public List<TransactionType> getTransactionTypeList()throws BaseException{
		List<TransactionType> list=new ArrayList<TransactionType>();

		try{
			list = masterSetupDao.getPropertyObjectList(TransactionType.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.transaction.type", new Object[]{}));
		}
		return list;
	}
	public void saveTransactionType(TransactionType transactionType)throws BaseException{
		try{

			List<TransactionType> duplicate = masterSetupDao.getTransactionTypeByCodeOrDesc(transactionType.getCode(), transactionType.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.transaction.type", new Object[]{}));
			masterSetupDao.save(transactionType);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.transaction.type", new Object[]{}));
		}
	}

	public void updateTransactionType(TransactionType transactionType)throws BaseException{
		try{
			List<TransactionType> duplicate = masterSetupDao.getTransactionTypeByCodeOrDesc(transactionType.getCode(), transactionType.getDesc());
			if(duplicate!=null){
				for(TransactionType t:duplicate){
					if(!t.getTransactionTypeId().equalsIgnoreCase(transactionType.getTransactionTypeId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.transaction.type", new Object[]{}));
				}
			}
			masterSetupDao.merge(transactionType);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.transaction.type", new Object[]{}));
		}
	}

	public void deleteTransactionTypes(List<TransactionType> transactionTypes)throws BaseException{
		try{
			for(TransactionType transactionType:transactionTypes){
				transactionType.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(transactionType);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.transaction.type", new Object[]{}));
		}
	}


	//Product
	public List<Product> getProductList()throws BaseException{
		List<Product> list=new ArrayList<Product>();

		try{
			list = masterSetupDao.getPropertyObjectList(Product.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.product", new Object[]{}));
		}
		return list;
	}
	public void saveProduct(Product product)throws BaseException{
		try{

			List<Product> duplicate = masterSetupDao.getProductByCodeOrDesc(product.getCode(), product.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.product", new Object[]{}));
			masterSetupDao.save(product);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.product", new Object[]{}));
		}
	}

	public void updateProduct(Product product)throws BaseException{
		try{
			List<Product> duplicate = masterSetupDao.getProductByCodeOrDesc(product.getCode(), product.getDesc());
			if(duplicate!=null){
				for(Product p:duplicate){
					if(!p.getProductId().equalsIgnoreCase(product.getProductId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.product", new Object[]{}));
				}
			}
			masterSetupDao.merge(product);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.product", new Object[]{}));
		}
	}

	public void deleteProducts(List<Product> products)throws BaseException{
		try{
			for(Product product:products){
				product.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(product);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.product", new Object[]{}));
		}
	}

	//Hotel Resort
	public List<HotelResort> getHotelResortList()throws BaseException{
		List<HotelResort> list=new ArrayList<HotelResort>();

		try{
			list = masterSetupDao.getPropertyObjectList(HotelResort.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.hotel.resort", new Object[]{}));
		}
		return list;
	}
	public void saveHotelResort(HotelResort hotelResort)throws BaseException{
		try{

			List<HotelResort> duplicate = masterSetupDao.getHotelResortByCodeOrDesc(hotelResort.getCode(), hotelResort.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.hotel.resort", new Object[]{}));
			masterSetupDao.save(hotelResort);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.hotel.resort", new Object[]{}));
		}
	}

	public void updateHotelResort(HotelResort hotelResort)throws BaseException{
		try{
			List<HotelResort> duplicate = masterSetupDao.getHotelResortByCodeOrDesc(hotelResort.getCode(), hotelResort.getDesc());
			if(duplicate!=null){
				for(HotelResort h:duplicate){
					if(!h.getHotelResortId().equalsIgnoreCase(hotelResort.getHotelResortId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.hotel.resort", new Object[]{}));
				}
			}
			masterSetupDao.merge(hotelResort);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.hotel.resort", new Object[]{}));
		}
	}

	public void deleteHotelResorts(List<HotelResort> hotelResorts)throws BaseException{
		try{
			for(HotelResort hr:hotelResorts){
				hr.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(hr);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.hotel.resort", new Object[]{}));
		}
	}

	//Hotel RCI Resort
	public List<HotelRciResort> getHotelRciResortList()throws BaseException{
		List<HotelRciResort> list=new ArrayList<HotelRciResort>();

		try{
			list = masterSetupDao.getPropertyObjectList(HotelRciResort.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.hotel.rci.resort", new Object[]{}));
		}
		return list;
	}
	public void saveHotelRciResort(HotelRciResort hotelRciResort)throws BaseException{
		try{

			List<HotelRciResort> duplicate = masterSetupDao.getHotelRciResortByCodeOrDesc(hotelRciResort.getCode(), hotelRciResort.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.hotel.rci.resort", new Object[]{}));
			masterSetupDao.save(hotelRciResort);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.hotel.rci.resort", new Object[]{}));
		}
	}

	public void updateHotelRciResort(HotelRciResort hotelRciResort)throws BaseException{
		try{
			List<HotelRciResort> duplicate = masterSetupDao.getHotelRciResortByCodeOrDesc(hotelRciResort.getCode(), hotelRciResort.getDesc());
			if(duplicate!=null){
				for(HotelRciResort r:duplicate){
					if(!r.getHotelRciResortId().equalsIgnoreCase(hotelRciResort.getHotelRciResortId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.hotel.rci.resort", new Object[]{}));
				}

			}
			masterSetupDao.merge(hotelRciResort);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.hotel.rci.resort", new Object[]{}));
		}
	}

	public void deleteHotelRciResorts(List<HotelRciResort> hotelRciResorts)throws BaseException{
		try{
			for(HotelRciResort hr:hotelRciResorts){
				hr.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(hr);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.hotel.rci.resort", new Object[]{}));
		}
	}

	//Hotel Room Type
	public List<HotelRoomType> getHotelRoomTypeList()throws BaseException{
		List<HotelRoomType> list=new ArrayList<HotelRoomType>();

		try{
			list = masterSetupDao.getPropertyObjectList(HotelRoomType.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.hotel.room.type", new Object[]{}));
		}
		return list;
	}
	public void saveHotelRoomType(HotelRoomType rommtype)throws BaseException{
		try{

			List<HotelRoomType> duplicate = masterSetupDao.getHotelRoomTypeByCodeOrDesc(rommtype.getCode(), rommtype.getDesc());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.hotel.room.type", new Object[]{}));
			masterSetupDao.save(rommtype);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.hotel.room.type", new Object[]{}));
		}
	}

	public void updateHotelRoomType(HotelRoomType rommtype)throws BaseException{
		try{
			List<HotelRoomType> duplicate = masterSetupDao.getHotelRoomTypeByCodeOrDesc(rommtype.getCode(), rommtype.getDesc());
			if(duplicate!=null){
				for(HotelRoomType t:duplicate){
					if(!t.getHotelRoomTypeId().equalsIgnoreCase(rommtype.getHotelRoomTypeId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.room.type", new Object[]{}));
				}
			}
			masterSetupDao.merge(rommtype);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.hotel.room.type", new Object[]{}));
		}
	}

	public void deleteHotelRoomTypes(List<HotelRoomType> rommtypes)throws BaseException{
		try{
			for(HotelRoomType hr:rommtypes){
				hr.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(hr);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.hotel.room.type", new Object[]{}));
		}
	}


	//Currency
	public List<Currency> getCurrencyList()throws BaseException{
		List<Currency> list=new ArrayList<Currency>();

		try{
			list = masterSetupDao.getPropertyObjectList(Currency.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.object", new Object[]{Currency.class.getSimpleName()}));
		}
		return list;
	}
	public void saveCurrency(Currency currency)throws BaseException{
		try{

			List<Currency> duplicate = masterSetupDao.getCurrencyByCodeOrDesc(currency.getCode(), currency.getDesc());
			
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.object", new Object[]{Currency.class.getSimpleName()}));
			masterSetupDao.save(currency);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.save.object", new Object[]{Currency.class.getSimpleName()}));
		}
	}

	public void updateCurrency(Currency currency)throws BaseException{
		try{
			List<Currency> duplicate = masterSetupDao.getCurrencyByCodeOrDesc(currency.getCode(), currency.getDesc());
			if(duplicate!=null){
				for(Currency c:duplicate){
					if(!c.getCurrencyId().equalsIgnoreCase(currency.getCurrencyId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.object", new Object[]{Currency.class.getSimpleName()}));
					}
			}
			masterSetupDao.merge(currency);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.update.object", new Object[]{Currency.class.getSimpleName()}));
		}
	}

	public void deleteCurrencies(List<Currency> currencies)throws BaseException{
		try{
			for(Currency currency:currencies){
				currency.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(currency);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.object", new Object[]{Currency.class.getSimpleName()}));
		}
	}
	//Territory
	public List<Territory> getTerritoryList()throws BaseException{
		List<Territory> list=new ArrayList<Territory>();

		try{
			list = masterSetupDao.getTerritoryByStateId();
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.list.territory", new Object[]{}));
		}
		return list;
	}
	public List<Territory> getTerritoryList(String stateId)throws BaseException{
		List<Territory> list=new ArrayList<Territory>();

		try{
			list = masterSetupDao.getTerritoryByStateId(stateId);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.list.territory", new Object[]{}));
		}
		return list;
	}
	public void saveTerritory(Territory territory,String stateId)throws BaseException{
		try{

			List<Territory> duplicate = masterSetupDao.getTerritoryByCodeOrDesc(territory.getCode(), territory.getDesc(),stateId);
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.territory", new Object[]{}));
			masterSetupDao.save(territory);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.territory", new Object[]{}));
		}
	}

	public void updateTerritory(Territory territory,String stateId)throws BaseException{
		try{
			List<Territory> duplicate = masterSetupDao.getTerritoryByCodeOrDesc(territory.getCode(), territory.getDesc(),stateId);
			if(duplicate!=null){
				for(Territory t:duplicate){
					if(!t.getTerritoryId().equalsIgnoreCase(territory.getTerritoryId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.territory", new Object[]{}));
				}
			}
			masterSetupDao.merge(territory);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.territory", new Object[]{}));
		}
	}

	public void deleteTerritory(List<Territory> territories)throws BaseException{
		try{
			for(Territory t:territories){
				t.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(t);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.territory", new Object[]{}));
		}
	}
	
	//CurrencyRate
	public List<CurrencyRate> getCurrencyRateListByCurrencyId(String currencyId)throws BaseException{
		List<CurrencyRate> list=new ArrayList<CurrencyRate>();

		try{
			Currency currency = (Currency) masterSetupDao.getObject(Currency.class, currencyId) ;
			list = masterSetupDao.getCurrencyRateListByCurrencyId(currency);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.object", new Object[]{CurrencyRate.class.getSimpleName()}));
		}
		return list;
	}
	public void saveCurrencyRate(CurrencyRate currencyRate)throws BaseException{
		try{

			masterSetupDao.save(currencyRate);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.save.object", new Object[]{CurrencyRate.class.getSimpleName()}));
		}
	}
	public void updateCurrencyRate(CurrencyRate currencyRate)throws BaseException{
		try{
			masterSetupDao.update(currencyRate);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.update.object", new Object[]{CurrencyRate.class.getSimpleName()}));
		}
	}
	public void deleteCurrencyRates(List<CurrencyRate> currencyRates)throws BaseException{
		try{
			for(CurrencyRate currencyRate:currencyRates){
				currencyRate.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(currencyRate);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.object", new Object[]{CurrencyRate.class.getSimpleName()}));
		}
	}
	
	//DocControl
	public List<DocControl> getDocControlList()throws BaseException{
		List<DocControl> list=new ArrayList<DocControl>();

		try{
			list = masterSetupDao.getPropertyObjectList(DocControl.class,"isDeleted",CommonConstant.NOT_DELETED); 
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.object", new Object[]{DocControl.class.getSimpleName()}));
		}
		return list;
	}
	public void saveDocControl(DocControl docControl)throws BaseException{
		try{

			masterSetupDao.save(docControl);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.save.object", new Object[]{DocControl.class.getSimpleName()}));
		}
	}
	public void updateDocControl(DocControl docControl)throws BaseException{
		try{
			masterSetupDao.update(docControl);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.update.object", new Object[]{DocControl.class.getSimpleName()}));
		}
	}
	public void deleteDocControls(List<DocControl> docControls)throws BaseException{
		try{
			for(DocControl docControl:docControls){
				docControl.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(docControl);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.object", new Object[]{DocControl.class.getSimpleName()}));
		}
	}
	public DocControl getDocControlByType(String type)throws BaseException{
		DocControl docControl=null;
		try{
			docControl=this.masterSetupDao.getDocControlByType(type);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.get.object", new Object[]{DocControl.class.getSimpleName()}));
		}
		return docControl;
	}
	
	public List<PaymentMode> getPaymentModeList()throws BaseException{
		List<PaymentMode> list=new ArrayList<PaymentMode>();

		try{
			list = masterSetupDao.getPropertyObjectList(PaymentMode.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.paymentmode", new Object[]{}));
		}
		return list;
	}
	
	
	
	//Calendar
	public List<Calendar> getCalendarList()throws BaseException{
		List<Calendar> list=new ArrayList<Calendar>();

		try{
			list = masterSetupDao.getPropertyObjectList(Calendar.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.calendar", new Object[]{}));
		}
		return list;
	}
	public void saveCalendar(Calendar calendar)throws BaseException{
		try{

			List<Calendar> duplicate = masterSetupDao.getCalendarByCodeOrDesc(calendar.getCode(), calendar.getDesc(),calendar.getDate());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.calendar", new Object[]{}));
			masterSetupDao.save(calendar);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.calendar", new Object[]{}));
		}
	}

	public void updateCalendar(Calendar calendar)throws BaseException{
		try{
			List<Calendar> duplicate = masterSetupDao.getCalendarByCodeOrDesc(calendar.getCode(), calendar.getDesc(),calendar.getDate());
			if(duplicate!=null){
				for(Calendar c:duplicate){
					if(!c.getCalendarId().equalsIgnoreCase(calendar.getCalendarId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.calendar", new Object[]{}));
				}
			}
			masterSetupDao.merge(calendar);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.calendar", new Object[]{}));
		}
	}

	public void deleteCalendar(List<Calendar> calendars)throws BaseException{
		try{
			for(Calendar c:calendars){
				c.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(c);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.calendar", new Object[]{}));
		}
	}
	
	//Installment Schema
	public List<InstallmentSchema> getInstallmentSchemaList()throws BaseException{
		List<InstallmentSchema> list=new ArrayList<InstallmentSchema>();

		try{
			list = masterSetupDao.getPropertyObjectList(InstallmentSchema.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.installment.schema", new Object[]{}));
		}
		return list;
	}
	public void saveInstallmentSchema(InstallmentSchema installmentSchema)throws BaseException{
		try{

			List<InstallmentSchema> duplicate = masterSetupDao.getInstallmentSchemaByCodeOrName(installmentSchema.getCode(), installmentSchema.getName());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.installment.schema", new Object[]{}));
			masterSetupDao.save(installmentSchema);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.installment.schema", new Object[]{}));
		}
	}

	public void updateInstallmentSchema(InstallmentSchema schema)throws BaseException{
		try{
			List<InstallmentSchema> duplicate = masterSetupDao.getInstallmentSchemaByCodeOrName(schema.getCode(), schema.getName());
			if(duplicate!=null){
				for(InstallmentSchema sc:duplicate){
					if(!sc.getInstallmentSchemaId().equalsIgnoreCase(schema.getInstallmentSchemaId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.installment.schema", new Object[]{}));
				}
			}
			masterSetupDao.merge(schema);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.installment.schema", new Object[]{}));
		}
	}

	public void deleteInstallmentSchema(List<InstallmentSchema> schemas)throws BaseException{
		try{
			for(InstallmentSchema s:schemas){
				s.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(s);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.installment.schema", new Object[]{}));
		}
	}
	
	//Down Payment Installment Schema
	public List<DownPaymentInstallmentSchema> getDownPaymentInstallmentSchemaList()throws BaseException{
		List<DownPaymentInstallmentSchema> list=new ArrayList<DownPaymentInstallmentSchema>();

		try{
			list = masterSetupDao.getPropertyObjectList(DownPaymentInstallmentSchema.class,"isDeleted",CommonConstant.NOT_DELETED);
		}catch(Exception ex){
			throw new BaseException(SpringUtils.getMessage("error.list.down.payment.installment.schema", new Object[]{}));
		}
		return list;
	}
	public void saveDownPaymentInstallmentSchema(DownPaymentInstallmentSchema schema)throws BaseException{
		try{

			List<DownPaymentInstallmentSchema> duplicate = masterSetupDao.getDownPaymentInstallmentSchemaByCodeOrName(schema.getCode(), schema.getName());
			if(duplicate!=null&&duplicate.size()>0)
				throw new BaseException(SpringUtils.getMessage("error.duplicate.down.payment.installment.schema", new Object[]{}));
			masterSetupDao.save(schema);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.create.down.payment.installment.schema", new Object[]{}));
		}
	}

	public void updateDownPaymentInstallmentSchema(DownPaymentInstallmentSchema schema)throws BaseException{
		try{
			List<DownPaymentInstallmentSchema> duplicate = masterSetupDao.getDownPaymentInstallmentSchemaByCodeOrName(schema.getCode(), schema.getName());
			if(duplicate!=null){
				for(DownPaymentInstallmentSchema sc:duplicate){
					if(!sc.getDownPaymentInstallmentSchemaId().equalsIgnoreCase(schema.getDownPaymentInstallmentSchemaId()))
						throw new BaseException(SpringUtils.getMessage("error.duplicate.down.payment.installment.schema", new Object[]{}));
				}
			}
			masterSetupDao.merge(schema);
		}catch(BaseException ex){
			ex.printStackTrace();
			throw ex;
		}
		catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.edit.down.payment.installment.schema", new Object[]{}));
		}
	}

	public void deleteDownPaymentInstallmentSchema(List<DownPaymentInstallmentSchema> schemas)throws BaseException{
		try{
			for(DownPaymentInstallmentSchema s:schemas){
				s.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(s);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.down.payment.installment.schema", new Object[]{}));
		}
	}
	
	public List<Remark> getRemarkList()throws BaseException{
		List<Remark> list=new ArrayList<Remark>();
		try{
			list=masterSetupDao.getRemarkList();
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.list.object", new Object[]{Remark.class.getSimpleName()}));
		}
		return list;
	}
	
	public void saveRemark(Remark remark)throws BaseException{
		try{
			masterSetupDao.save(remark);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.save.object", new Object[]{Remark.class.getSimpleName()}));
		}
	}
	
	public void updateRemark(Remark remark)throws BaseException{
		try{
			masterSetupDao.update(remark);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.update.object", new Object[]{Remark.class.getSimpleName()}));
		}
	}
	
	public void deleteRemark(List<Remark> deleteList)throws BaseException{
		try{
			for(Remark remark : deleteList){
				remark.setIsDeleted(CommonConstant.IS_DELETED);
				masterSetupDao.update(remark);
			}
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.delete.object", new Object[]{Remark.class.getSimpleName()}));
		}
	}
}
